/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.variable.dtgenerator;


import com.inspur.edp.caf.generator.module.ModuleGenerator;
import com.inspur.edp.cef.designtime.api.variable.CommonVariableEntity;
import com.inspur.edp.cef.entity.dependenceTemp.DataValidator;
import com.inspur.edp.cef.generator.apiGenerator.CefApiGenerator;
import com.inspur.edp.cef.generator.configGenerator.CefConfigGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.CefCoreGenerator;
import com.inspur.edp.cef.generator.entityGenerator.BaseEntityGenerator;
import com.inspur.edp.cef.generator.overall.CefGenerator;
import com.inspur.edp.cef.generator.overall.CefGeneratorContext;
import com.inspur.edp.cef.generator.overall.ICefGeneratorContext;
import com.inspur.edp.cef.variable.dtgenerator.api.VariableApiGenerator;
import com.inspur.edp.cef.variable.dtgenerator.core.VariableCoreGenerator;
import com.inspur.edp.cef.variable.dtgenerator.entity.VariableEntityGenerator;
import com.inspur.edp.jittojava.context.JitContext;
import com.inspur.edp.lcm.metadata.api.entity.GspMetadata;

public class VariableGenerator extends CefGenerator
{
	private CommonVariableEntity variableEntity;

	private ICefGeneratorContext privateCefGeneratorContext;
	protected final ICefGeneratorContext getCefGeneratorContext()
	{
		return privateCefGeneratorContext;
	}
	public VariableGenerator(String path, CommonVariableEntity variableEntity, ICefGeneratorContext refProjContext, boolean pre, JitContext metadataJitContext)
	{
		super(path, refProjContext.getMetadata(), pre, null, metadataJitContext);
		DataValidator.checkForNullReference(refProjContext, "refProjContext");
		DataValidator.checkForNullReference(refProjContext.getMetadata(), "refProjContext.Metadata");
		DataValidator.checkForNullReference(variableEntity, "variableEntity");
		DataValidator.checkForNullReference(metadataJitContext, "metadataJitContext");
		this.variableEntity = variableEntity;
		privateCefGeneratorContext = refProjContext;
	}

	public VariableGenerator(String path, CommonVariableEntity variableEntity, ICefGeneratorContext refProjContext
			, GspMetadata metadata, CefGeneratorContext refGenCtx, ModuleGenerator refGenerator, JitContext metadataJITContext)
	{
		super(path, metadata, refGenCtx, refGenerator, metadataJITContext);
		DataValidator.checkForNullReference(refProjContext, "refProjContext");
		DataValidator.checkForNullReference(refProjContext.getMetadata(), "refProjContext.Metadata");
		DataValidator.checkForNullReference(variableEntity, "variableEntity");
		DataValidator.checkForNullReference(metadataJITContext, "metadataJitContext");
		this.variableEntity = variableEntity;
		privateCefGeneratorContext = refProjContext;
	}

	public VariableGeneratorContext getVariableGeneratorContext(){return  (VariableGeneratorContext)super.getContext();}

	@Override
	protected final CefGeneratorContext createCefGeneratorContext()
	{
		VariableGeneratorContext rez = CreateVarGeneratorContext();
		rez.setCefGeneratorContext(getCefGeneratorContext());
		return rez;
	}

	protected VariableGeneratorContext CreateVarGeneratorContext()
	{
		VariableGeneratorContext ctx = new VariableGeneratorContext(variableEntity);
		if (preGenerating)
		{
			ctx.setRefProjectGenerator(super.getMetadataJITContext().getApiModuleGenerator());
		}
		else
		{
			ctx.setRefProjectGenerator(super.getMetadataJITContext().getCoreModuleGenerator());
		}
		return ctx;
	}

		///#endregion
	@Override
	protected CefApiGenerator createApiGenerator()
	{
		return new VariableApiGenerator(getVariableGeneratorContext());
	}

	@Override
	protected CefCoreGenerator createCoreGenerator()
	{
		return new VariableCoreGenerator(getVariableGeneratorContext());
	}

	@Override
	protected BaseEntityGenerator createEntityGenerator()
	{
		return new VariableEntityGenerator(getVariableGeneratorContext());
	}


		///#region 编译执行完之后要执行的逻辑
	@Override
	protected void afterGenerate()
	{
		super.afterGenerate();
		//var configGen = new VarConfigGenerator(Context);
		//configGen.Generate();
		//Context.config = configGen.config;
	}

		///#endregion


	public boolean isHasRepository() {
		return  false;
	}

	@Override
	protected boolean getHasRepository() {
		return false;
	}

	@Override
	protected CefConfigGenerator createConfigGenerator(){return null;}
}
